<?php
/**
 * | @author 李鹏博^life <907215837@qq.com>
 * +----------------------------------------------------------------------
 * | @copyright 2019 - 2019 HQ
 * +----------------------------------------------------------------------
 * | @version $Id: 2019/5/17 14:02 wwwroot fromId.php 韩威兵^life $
 * +----------------------------------------------------------------------
 */


namespace app\common\common\model\order;

use app\common\common\model\NewBase;

class fromId extends NewBase
{

    protected $table = 'wechat_sms_form';
    //错误消息
    public $error = '';
    //状态值
    public $status = true;
    //其他附带信息
    public $data = [];


    /**
     * 添加数据
     * @param $data 所添加的数据
     * @return int
     */
    public function insertData($data){
       return  $this->insert($data);
    }

    /**
     * 销毁formid
     * @param $where
     * @param $data
     * @return bool
     * @throws \think\Exception
     */
    public function updateWhere($where,$data){
        if(empty($where) || empty($data)){
            return false;
        }
        return $res = $this->where($where)->update($data);

    }
    /**
     * 不带分页的多条查询
     * @param $where
     * @return false|\PDOStatement|string|\think\Collection
     */
    public function allByWhere($where){
        return $this->where($where)->select()->ToArray();
    }

    /**
     * 带分页的查询
     * @param $where
     * @param $limit
     * @param string $order
     * @return false|\PDOStatement|string|\think\Collection
     */
    public function selectByWhere($where, $limit, $order='id desc'){
        $list = $this->where($where)->limit($limit)->order($order)->select()->ToArray();
        $count = $this->where($where)->count();
        $this->data['count'] = $count;
        return $list;
    }

    /**
     * 查询数据是否存在
     * @param $where
     * @return array|false|\PDOStatement|string|\think\Model
     */
    public function countByWhere($where){
        if(empty($where)){
            return false;
        }
        $res = $this->where($where)->count();
        return $res;
    }

    /**
     * 查询单条数据
     * @param $where
     * @return array|false|\PDOStatement|string|\think\Model
     */
    public function findByWhere($where){
        if(empty($where)){
            return false;
        }
        $res = $this->whereTime('expiration_time', 'd')->where($where)->find();
        return $res;
    }

    /**
     * 根据时间和条件查找数据
     * @param $where
     * @return array|false|\PDOStatement|string|\think\Model
     */
    public function findBywhereTime($where){
        if(empty($where)){
            return false;
        }
        $res = $this->where('expiration_time','> time',date('Y-m-d H:i:s',strtotime('-7 days')))->where($where)->find();
        return $res;
    }
}